package DecChallenges;

public class Day31_P1578 {
    public static void main(String[] args) {
        String colors = "abaac";
        int[] neededTime = {1,2,3,4,5};
        System.out.println(minCost(colors, neededTime));
    }
    public static int minCost(String colors, int[] neededTime) {
        int ans = 0;
        int consSum = neededTime[0];
        int consMax = neededTime[0];
        char[] str = colors.toCharArray();
        for(int i = 1; i < str.length; i++) {
            if(str[i] == str[i - 1]) {
                consSum += neededTime[i];
                consMax = Math.max(consMax, neededTime[i]);
            }else {
                ans += (consSum - consMax);
                consSum = neededTime[i];
                consMax = neededTime[i];
            }
        }
        return ans + (consSum - consMax);
    }
}
